//
//  SuperVC.m
//  xychain_DM_iOS
//
//  Created by Jpwang on 2018/5/21.
//  Copyright © 2018年 Jpwang. All rights reserved.
//

#import "SuperVC.h"


@interface SuperVC () {
    MBProgressHUD *hud;
}

@property(strong, nonatomic) UIPanGestureRecognizer *panGesture;
@property(weak, nonatomic) IBOutlet UIImageView *contentIv;

@end

@implementation SuperVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.contentIv) {
        self.contentIv.layer.cornerRadius = globalRadius;
    }
    [self addGesture];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)addGesture {
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    // handleNavigationTransition:为系统私有API,即系统自带侧滑手势的回调方法，我们在自己的手势上直接用它的回调方法
    self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    self.panGesture.delegate = (id)self; // 设置手势代理，拦截手势触发
    [self.view addGestureRecognizer:self.panGesture];
    // 一定要禁止系统自带的滑动手势
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

- (void)removeGesture {
    if (self.panGesture) {
        [self.view removeGestureRecognizer:self.panGesture];
    }
}


#pragma mark 加载效果
- (void)showSuccessed:(NSString *)text {
    [SVProgressHUD showSuccessWithStatus:text];
}

- (void)showError:(NSString *)text {
    [SVProgressHUD showErrorWithStatus:text];
}

- (void)showText:(NSString *)text {
    [SVProgressHUD resetOffsetFromCenter];
    [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, 100)];
    [SVProgressHUD showWithStatus:text maskType:SVProgressHUDMaskTypeBlack];
}

- (void)hideText {
    [SVProgressHUD dismiss];
}

- (void)showLoading:(NSString *)text {
    hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.backgroundView.color = [UIColor colorWithWhite:0.f alpha:0.3f];
    hud.bezelView.color = [UIColor whiteColor];
    hud.minSize = CGSizeMake(90, 50);
    hud.margin = 10;
    hud.label.font = [UIFont systemFontOfSize:13];
    hud.label.text = text;
}

- (void)hideLoading {
    if (hud) {
        [hud hideAnimated:YES];
    }
}

- (NSMutableAttributedString *)handleBigSmallText:(NSString *)text {
    NSRange range = [text rangeOfString:@"."];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    if (range.location != NSNotFound) {
        [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, range.location)];
        [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(range.location, text.length-range.location)];
    } else {
        [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, text.length)];
    }
    return attributedString;
}


- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (BOOL)isWalletAddress:(NSString *)str {
    if (![str hasPrefix:@"0x"]) {
        return str.length == 40 && isHexNumber(str);
    } else {
        return str.length == 42 && isHexNumber([str substringFromIndex:2]);
    }
}

- (void)setUIAlertController:(UIAlertController *)alert MessageAlign:(NSTextAlignment)align {
    UIView *subView1 = alert.view.subviews[0];
    UIView *subView2 = subView1.subviews[0];
    UIView *subView3 = subView2.subviews[0];
    UIView *subView4 = subView3.subviews[0];
    UIView *subView5 = subView4.subviews[0];
    //分别拿到title 和 message 可以分别设置他们的对齐属性
    UIView *message = subView5.subviews[1];
    if (![message isKindOfClass:[UILabel class]]) {
        message = subView5.subviews[0];
    }
    @try {
        ((UILabel *)message).textAlignment = align;
    } @catch (NSException *exception) {
        
    }
    
}


@end
